/*
 *
 *  Copyright (C) 2010 Tal Eisenberg
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package tal.drivechain.variable;

import java.io.Serializable;
import java.util.List;
import tal.drivechain.chain.ChainNode;

/**
 *
 * @author Main
 */
public class Command implements Serializable {
    private String name;
    private List<Variable> parameters;
    
    public Command(String name, List<Variable> parameters) throws IllegalArgumentException{
        this.name = name;
        if (!VarTable.isValidVarName(name))
            throw new IllegalArgumentException("Invalid variable name: " + name);
        this.parameters = parameters;
    }
    
    public String getName() { return name; }
    public List<Variable> getParameters() { return parameters; }

    public void setName(String name) {
        this.name = name;
    }
    
    public String toString(ChainNode context) {
        parameters.toString();
        String ret = getName() + "{";
        if (parameters!=null && !parameters.isEmpty()) {
            for (Variable var : parameters) {
                ret += var.toString(context) + ", ";
            }
            ret = ret.substring(0, ret.length()-2);
        }
        return ret + "}";
    }
}
